package com.jxmcloud.business.cut.json;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

import com.jxmcloud.business.cut.model.json.ConfigGlobalGlobal;
import com.jxmcloud.business.cut.service.json.IConfigGlobalGlobalService;
import com.jxmcloud.business.cut.vo.json.ConfigGlobalGlobalVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class DataConfigGlobalGlobalLoader {
    @Resource
    private IConfigGlobalGlobalService configGlobalGlobalService;
    //
    private ConfigGlobalGlobalVo data = new ConfigGlobalGlobalVo();

    public boolean loadFromDb() {
        try {
            ConfigGlobalGlobal configGlobalGlobal = this.configGlobalGlobalService.lambdaQuery().one();
            if(ObjectUtil.isNotEmpty(configGlobalGlobal)){

                this.data.setPowerLimit(configGlobalGlobal.getPowerLimit());

                this.data.setItemIdCash(configGlobalGlobal.getItemIdCash());

                this.data.setItemIdLottery(configGlobalGlobal.getItemIdLottery());

                this.data.setItemIdClover(configGlobalGlobal.getItemIdClover());

                this.data.setItemIdCard(configGlobalGlobal.getItemIdCard());

                this.data.setItemIdPool(configGlobalGlobal.getItemIdPool());

                this.data.setItemIdCardChip(configGlobalGlobal.getItemIdCardChip());

                this.data.setItemIdOpenLive(configGlobalGlobal.getItemIdOpenLive());

                this.data.setUserActValidTime(configGlobalGlobal.getUserActValidTime());

                this.data.setItemIdApproveValue(configGlobalGlobal.getItemIdApproveValue());

                this.data.setItemIdCashCoin(configGlobalGlobal.getItemIdCashCoin());

                this.data.setCashCoinMax(configGlobalGlobal.getCashCoinMax());

                this.data.setNewersCoin(configGlobalGlobal.getNewersCoin());

            }
            log.info("加载configGlobalGlobal表数据成功！");
            return true;
        } catch (Exception e) {
            log.error("加载数据失败！{}", e);
        }
        return false;
    }

    public ConfigGlobalGlobalVo getConfigGlobalGlobal() {
        return this.data; // 返回不可变Map
    }

    public boolean reloadFromDb() {
        this.data = new ConfigGlobalGlobalVo();
        return this.loadFromDb();
    }

}